package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

@Component("multiInstanceCompleteTask")
public class MultiInstanceCompleteTask {

    /**
     * 多实例用户任务完成时需要触发的方法
     * ${multiInstanceCompleteTask.completeAllTask(execution)}
     * @param execution
     * @return
     *      false  表示会签任务还没有结束
     *      true   表示会签任务结束
     */
    public boolean completeAllTask(DelegateExecution execution) {
        System.out.println("总的会签任务数量：" + execution.getVariable("nrOfInstances")
                + "当前获取的会签任务数量：" + execution.getVariable("nrOfActiveInstances")
                + " - " + "已经完成的会签任务数量：" + execution.getVariable("nrOfCompletedInstances"));

        //全部同意才算通过
        Integer nrOfInstances = (Integer) execution.getVariable("nrOfInstances");
        Integer nrOfCompletedInstances = (Integer) execution.getVariable("nrOfCompletedInstances");
        return nrOfCompletedInstances >= nrOfInstances;
    }
}
